the main page is simply a little form asking to introduce a new customer...=
.. (the problem is not when you try to create the XML file for the first tim=
e, but something on getElementsByTagName, that is when you try to reopen th=
e file... for example for a second customer....
if (isset($_GET['add_customer']) && isset($_GET['new_customer_name'=
])
&& isset($_GET['new_customer_phone'])) {
$c =3D new customer($_GET['new_customer_name'], $_GET['new_=
customer_phone']);
$c->addXMLCustomer($doc, $root);
}
$doc->save($xmlfile);
}
else {
$doc =3D new DOMDocument();
$doc->load($xmlfile);
$root =3D $doc->getElementsByTagName("customers");
if (isset($_GET['add_customer']) && isset($_GET['new_customer_name'=
])
&& isset($_GET['new_customer_phone'])) {
$c =3D new customer($_GET['new_customer_name'], $_GET['new_=
customer_phone']);
$c->addXMLCustomer($doc, $root);
}
$doc->save($xmlfile);
}
?>
Any suggestions??
Thks
Maurizio
--
The information transmitted is intended for the person or entity to which i=
t is addressed and may contain confidential and/or privileged material. Any=
review, retransmission, dissemination or other use of, or taking of any ac=
tion in reliance upon, this information by persons or entities other than t=
he intended recipient is prohibited. If you received this in error, please =
contact the sender and delete the material from any computer.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Problem with DOM
am 12.05.2009 19:16:32 von Niel Archer
> Hi all,
>
> I'm trying to create some XML from PHP code to save data about customers, but I found many problem and it doesn't work.
>
> The class Customer is quite simple I put it right below
>
>
>
> class customer {
> var $name;
> var $phone;
>
> function customer($name, $phone) {
> $this->name = $name;
> $this->phone = $phone;
> }
>
> function getName() {
> return $name;
> }
>
> function setName($name) {
> $this->name = $name;
> }
>
> function getPhone() {
> return $phone;
> }
>
> function setPhone($phone) {
> $this->phone = $phone;
> }
>
> function addXMLCustomer($dom, $root) {
> $customer = $dom->createElement('customer');
>
> $name_at = $dom->createAttribute('name');
> $customer->appendChild($name_at);
> $name_at_val = $dom->createTextNode($this->name);
> $name_at->appendChild($name_at_val);
>
> $phone_at = $dom->createAttribute('phone');
> $customer->appendChild($phone_at);
> $phone_at_val = $dom->createTextNode($this->phone);
> $phone_at->appendChild($phone_at_val);
>
> $root->appendChild($customer);
>
> }
> }
>
> ?>
>
> the main page is simply a little form asking to introduce a new customer.... (the problem is not when you try to create the XML file for the first time, but something on getElementsByTagName, that is when you try to reopen the file... for example for a second customer....
>
>
>
It looks to me that you are creating a new DOM object for the file
existing condition, but not loading the actual file into the object with
$doc->load() or similar. Consequently you are creating a new file with
single entry each time.
Also, I wonder why your new DOMDocument()s have different parameters?
Wouldn't it be wise to make them the same to avoid possible problems?
> Thks
> Maurizio
>
> --
> The information transmitted is intended for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
Niel Archer
niel.archer (at) blueyonder.co.uk
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Problem with DOM
am 12.05.2009 21:09:31 von Bellemo Maurizio
Hi
I'm sorry, but I don't understand well what you are trying to tell me.....
Let's imagine I want to modify an existent XML file called customers.xml
I should do this steps
$doc =3D new DOMDocument();
$doc->load('customers.xml');
$root =3D $doc->getElementsByTagName("customers"); // to take the root
..... // create one customer
$doc->save('customer.xml'); // to save the changes
that is exactly what I did in the else part (in the if, in the case the fil=
e customers.xml didn't exist, I create the file with only the root node).
Isn't is right?
For what concerns the two type of DOMDocument istantiation.... I forgot to =
chance them both :)
Thks
Maurizio Bellemo
Sytel Reply Deutschland
__________________
m.bellemo@reply.it
Prinzenalle 7
40549 Düsseldorf
GERMANY
________________________________________
From: Niel Archer [not@chance.now]
Sent: Tuesday, May 12, 2009 7:16 PM
To: php-windows@lists.php.net
Subject: Re: [PHP-WIN] Problem with DOM
> Hi all,
>
> I'm trying to create some XML from PHP code to save data about customers,=
but I found many problem and it doesn't work.
>
> The class Customer is quite simple I put it right below
>
>
>
> class customer {
> var $name;
> var $phone;
>
> function customer($name, $phone) {
> $this->name =3D $name;
> $this->phone =3D $phone;
> }
>
> function getName() {
> return $name;
> }
>
> function setName($name) {
> $this->name =3D $name;
> }
>
> function getPhone() {
> return $phone;
> }
>
> function setPhone($phone) {
> $this->phone =3D $phone;
> }
>
> function addXMLCustomer($dom, $root) {
> $customer =3D $dom->createElement('customer');
>
> $name_at =3D $dom->createAttribute('name');
> $customer->appendChild($name_at);
> $name_at_val =3D $dom->createTextNode($this->name);
> $name_at->appendChild($name_at_val);
>
> $phone_at =3D $dom->createAttribute('phone');
> $customer->appendChild($phone_at);
> $phone_at_val =3D $dom->createTextNode($this->phone);
> $phone_at->appendChild($phone_at_val);
>
> $root->appendChild($customer);
>
> }
> }
>
> ?>
>
> the main page is simply a little form asking to introduce a new customer.=
.... (the problem is not when you try to create the XML file for the first t=
ime, but something on getElementsByTagName, that is when you try to reopen =
the file... for example for a second customer....
>
>
>
It looks to me that you are creating a new DOM object for the file
existing condition, but not loading the actual file into the object with
$doc->load() or similar. Consequently you are creating a new file with
single entry each time.
Also, I wonder why your new DOMDocument()s have different parameters?
Wouldn't it be wise to make them the same to avoid possible problems?
> Thks
> Maurizio
>
> --
> The information transmitted is intended for the person or entity to which=
it is addressed and may contain confidential and/or privileged material. A=
ny review, retransmission, dissemination or other use of, or taking of any =
action in reliance upon, this information by persons or entities other than=
the intended recipient is prohibited. If you received this in error, pleas=
e contact the sender and delete the material from any computer.
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
Niel Archer
niel.archer (at) blueyonder.co.uk
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
The information transmitted is intended for the person or entity to which i=
t is addressed and may contain confidential and/or privileged material. Any=
review, retransmission, dissemination or other use of, or taking of any ac=
tion in reliance upon, this information by persons or entities other than t=
he intended recipient is prohibited. If you received this in error, please =
contact the sender and delete the material from any computer.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Problem with DOM
am 12.05.2009 22:05:24 von Niel Archer
> Hi
> I'm sorry, but I don't understand well what you are trying to tell me.....
>=20
> Let's imagine I want to modify an existent XML file called customers.xml
>=20
> I should do this steps
>=20
> $doc =3D new DOMDocument();
> $doc->load('customers.xml');
> $root =3D $doc->getElementsByTagName("customers"); // to take the root
>=20
> .... // create one customer
>=20
> $doc->save('customer.xml'); // to save the changes
>=20
> that is exactly what I did in the else part (in the if, in the case the f=
ile customers.xml didn't exist, I create the file with only the root node).
> Isn't is right?
Apologies. I missed the '!' in the if and got the logic reversed.
You do not say what does or does not happen on the second attempt? Am I
correct in assuming there is no change?
> For what concerns the two type of DOMDocument istantiation.... I forgot t=
o chance them both :)
>=20
> Thks
> Maurizio Bellemo
> Sytel Reply Deutschland
> __________________
>=20
> m.bellemo@reply.it
> Prinzenalle 7
> 40549 Düsseldorf
> GERMANY
> ________________________________________
> From: Niel Archer [not@chance.now]
> Sent: Tuesday, May 12, 2009 7:16 PM
> To: php-windows@lists.php.net
> Subject: Re: [PHP-WIN] Problem with DOM
>=20
> > Hi all,
> >
> > I'm trying to create some XML from PHP code to save data about customer=
s, but I found many problem and it doesn't work.
> >
> > The class Customer is quite simple I put it right below
> >
> >
> >
> > class customer {
> > var $name;
> > var $phone;
> >
> > function customer($name, $phone) {
> > $this->name =3D $name;
> > $this->phone =3D $phone;
> > }
> >
> > function getName() {
> > return $name;
> > }
> >
> > function setName($name) {
> > $this->name =3D $name;
> > }
> >
> > function getPhone() {
> > return $phone;
> > }
> >
> > function setPhone($phone) {
> > $this->phone =3D $phone;
> > }
> >
> > function addXMLCustomer($dom, $root) {
> > $customer =3D $dom->createElement('customer');
> >
> > $name_at =3D $dom->createAttribute('name');
> > $customer->appendChild($name_at);
> > $name_at_val =3D $dom->createTextNode($this->name);
> > $name_at->appendChild($name_at_val);
> >
> > $phone_at =3D $dom->createAttribute('phone');
> > $customer->appendChild($phone_at);
> > $phone_at_val =3D $dom->createTextNode($this->phone);
> > $phone_at->appendChild($phone_at_val);
> >
> > $root->appendChild($customer);
> >
> > }
> > }
> >
> > ?>
> >
> > the main page is simply a little form asking to introduce a new custome=
r.... (the problem is not when you try to create the XML file for the first=
time, but something on getElementsByTagName, that is when you try to reope=
n the file... for example for a second customer....
> >
> >
> >
> >
> >
> >
> > Any suggestions??
>=20
> It looks to me that you are creating a new DOM object for the file
> existing condition, but not loading the actual file into the object with
> $doc->load() or similar. Consequently you are creating a new file with
> single entry each time.
> Also, I wonder why your new DOMDocument()s have different parameters?
> Wouldn't it be wise to make them the same to avoid possible problems?
>=20
>=20
> > Thks
> > Maurizio
> >
> > --
> > The information transmitted is intended for the person or entity to whi=
ch it is addressed and may contain confidential and/or privileged material.=
Any review, retransmission, dissemination or other use of, or taking of an=
y action in reliance upon, this information by persons or entities other th=
an the intended recipient is prohibited. If you received this in error, ple=
ase contact the sender and delete the material from any computer.
> >
> > --
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>=20
> --
> Niel Archer
> niel.archer (at) blueyonder.co.uk
>=20
>=20
>=20
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
>=20
> --
> The information transmitted is intended for the person or entity to which=
it is addressed and may contain confidential and/or privileged material. A=
ny review, retransmission, dissemination or other use of, or taking of any =
action in reliance upon, this information by persons or entities other than=
the intended recipient is prohibited. If you received this in error, pleas=
e contact the sender and delete the material from any computer.
>=20
> --=20
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
--
Niel Archer
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Problem with DOM
am 12.05.2009 22:37:33 von Niel Archer
> > Hi
> > I'm sorry, but I don't understand well what you are trying to tell me.....
> >=20
> > Let's imagine I want to modify an existent XML file called customers.xm=
l
> >=20
> > I should do this steps
> >=20
> > $doc =3D new DOMDocument();
> > $doc->load('customers.xml');
> > $root =3D $doc->getElementsByTagName("customers"); // to take the root
> >=20
> > .... // create one customer
> >=20
> > $doc->save('customer.xml'); // to save the changes
> >=20
> > that is exactly what I did in the else part (in the if, in the case the=
file customers.xml didn't exist, I create the file with only the root node=
).
> > Isn't is right?
>=20
> Apologies. I missed the '!' in the if and got the logic reversed.
>=20
> You do not say what does or does not happen on the second attempt? Am I
> correct in assuming there is no change?
The problem appears to be with the line:
$root->appendChild($customer);
in your addXMLCustomer method.
This give me the following error:
PHP Fatal error: Call to undefined method DOMNodeList::appendChild() in D:=
\Scripts\PHP\TESTS\DOM-test.php
> > For what concerns the two type of DOMDocument istantiation.... I forgot=
to chance them both :)
> >=20
> > Thks
> > Maurizio Bellemo
> > Sytel Reply Deutschland
> > __________________
> >=20
> > m.bellemo@reply.it
> > Prinzenalle 7
> > 40549 Düsseldorf
> > GERMANY
> > ________________________________________
> > From: Niel Archer [not@chance.now]
> > Sent: Tuesday, May 12, 2009 7:16 PM
> > To: php-windows@lists.php.net
> > Subject: Re: [PHP-WIN] Problem with DOM
> >=20
> > > Hi all,
> > >
> > > I'm trying to create some XML from PHP code to save data about custom=
ers, but I found many problem and it doesn't work.
> > >
> > > The class Customer is quite simple I put it right below
> > >
> > >
> > >
> > > class customer {
> > > var $name;
> > > var $phone;
> > >
> > > function customer($name, $phone) {
> > > $this->name =3D $name;
> > > $this->phone =3D $phone;
> > > }
> > >
> > > function getName() {
> > > return $name;
> > > }
> > >
> > > function setName($name) {
> > > $this->name =3D $name;
> > > }
> > >
> > > function getPhone() {
> > > return $phone;
> > > }
> > >
> > > function setPhone($phone) {
> > > $this->phone =3D $phone;
> > > }
> > >
> > > function addXMLCustomer($dom, $root) {
> > > $customer =3D $dom->createElement('customer');
> > >
> > > $name_at =3D $dom->createAttribute('name');
> > > $customer->appendChild($name_at);
> > > $name_at_val =3D $dom->createTextNode($this->name);
> > > $name_at->appendChild($name_at_val);
> > >
> > > $phone_at =3D $dom->createAttribute('phone');
> > > $customer->appendChild($phone_at);
> > > $phone_at_val =3D $dom->createTextNode($this->phone);
> > > $phone_at->appendChild($phone_at_val);
> > >
> > > $root->appendChild($customer);
> > >
> > > }
> > > }
> > >
> > > ?>
> > >
> > > the main page is simply a little form asking to introduce a new custo=
mer.... (the problem is not when you try to create the XML file for the fir=
st time, but something on getElementsByTagName, that is when you try to reo=
pen the file... for example for a second customer....
> > >
> > >
> > >
> > >
> > >
> > >
> > > Any suggestions??
> >=20
> > It looks to me that you are creating a new DOM object for the file
> > existing condition, but not loading the actual file into the object wit=
h
> > $doc->load() or similar. Consequently you are creating a new file with
> > single entry each time.
> > Also, I wonder why your new DOMDocument()s have different parameters?
> > Wouldn't it be wise to make them the same to avoid possible problems?
> >=20
> >=20
> > > Thks
> > > Maurizio
> > >
> > > --
> > > The information transmitted is intended for the person or entity to w=
hich it is addressed and may contain confidential and/or privileged materia=
l. Any review, retransmission, dissemination or other use of, or taking of =
any action in reliance upon, this information by persons or entities other =
than the intended recipient is prohibited. If you received this in error, p=
lease contact the sender and delete the material from any computer.
> > >
> > > --
> > > PHP Windows Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >=20
> > --
> > Niel Archer
> > niel.archer (at) blueyonder.co.uk
> >=20
> >=20
> >=20
> > --
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >=20
> >=20
> > --
> > The information transmitted is intended for the person or entity to whi=
ch it is addressed and may contain confidential and/or privileged material.=
Any review, retransmission, dissemination or other use of, or taking of an=
y action in reliance upon, this information by persons or entities other th=
an the intended recipient is prohibited. If you received this in error, ple=
ase contact the sender and delete the material from any computer.
> >=20
> > --=20
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >=20
>=20
> --
> Niel Archer
>=20
>=20
>=20
> --=20
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
--
Niel Archer
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Problem with DOM
am 13.05.2009 00:40:06 von Niel Archer
Hi
Got it working as expected. Try the following modified class